/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package progdynamique;

import java.io.File;

/**
 *Labels for ProgDynamique instances.
 * 
 * @author Guillaume
 */
public class Label {
    private int currStage; //the current stage in the problem (i=k => items 1 to k could have been choosen in solution)
    private double weight;
    private double profit;
    private Solution solAssociated;
    
    
    public Label(int currStage, double weight, double profit, Solution solAssociated) {
        this.currStage = currStage;
        this.weight = weight;
        this.profit = profit;
        this.solAssociated = solAssociated;
    }
    
    /**
     * Is this label dominates the label otherLabel.
     * <p>
     * @param otherLabel the label we wants to know if it is dominated by this label.
     * @return true if this label dominates otherLabel, false if it's not.
     */
    public boolean isDominates(Label otherLabel){    
        if(weight > otherLabel.getWeight() && profit >= otherLabel.getProfit()
                || weight == otherLabel.getWeight() && profit > otherLabel.getProfit()){
            return true;
        }
        return false;
    }
    
    /**
     * Return true if the weight of this label plus the relaxation of the knapsack problem
     * on the restants items is less than the weight of an incumbent solution.
     * <p>
     * items restants are determined by the fact that a label have a current stage i which
     * means that objets 1 to i could have been choosen. That's also means that the items
     * which will could be choosen are items i+1 to n, so this method calculate the relaxation of
     * the knapsack problem for items i+1 to n (n=total number of item).
     * 
     * @param dat the data for the knapsack problem.
     * @param incumbent the incumbent solution which be compared to the hypothetic best objective archievable of this label.
     * @return true if the weight of this label plus the relaxation of the knapsack problem
     * on the restants items is less than the weight of an incumbent solution.
     */
    public boolean isPartialPlusRelaxWorseThan(DataProblem dat, double incumbent){
        double z=this.getProfit();
        double currCap = dat.getCapSac() - this.getWeight();
        for (int i = this.currStage + 1; i < dat.getNbItems(); i++) {
            if(dat.getListItems().get(i).getWeight() < currCap){
                currCap-=dat.getListItems().get(i).getWeight();
                z+=dat.getListItems().get(i).getProfit();
            }else{ // ici les poids doivent êtres positif, sinon rajouter condition en plus...
                z+=currCap*dat.getListItems().get(i).getProfit()/dat.getListItems().get(i).getWeight();
                return z <= incumbent;
            }
        }
        
        return z <= incumbent;
    }

    public int getCurrStage() {
        return currStage;
    }

    public double getWeight() {
        return weight;
    }

    public double getProfit() {
        return profit;
    }

    public Solution getSolAssociated() {
        return solAssociated;
    }
    
}
